<template>
  <li>
    <label>
      <!-- v-model 具有双向绑定的能力， 为了保障单向数据流，所以不允许 -->
      <input
        type="checkbox"
        :checked="task.isDone"
        @change="changeIpt(task.id)"
      />
      <span :class="{ cls: task.isDone }">{{ task.name }}</span>
    </label>
    <button class="btn btn-danger" @click="fn(task.id)">删除</button>
  </li>
</template>

<script>
export default {
  // 接收父组件传入的数据
  props: ['task', 'del', 'changeIpt'],
  methods: {
    fn(id) {
      const bool = confirm('确认删除任务吗？')
      if (bool) {
        this.del(id)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.cls {
  text-decoration: line-through;
}

/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}

li:hover button {
  display: block;
}

li:hover {
  background-color: #eee;
}

input {
  margin-right: 10px;
}
</style>
